package com.logistics.menu.entity.model;

import com.logistics.menu.entity.domain.Menu;
import com.logistics.route.entity.model.RouteRow;
import com.logistics.utils.aspect.annotation.Dictionary;
import com.logistics.utils.tool.DateUtils;
import com.logistics.utils.tool.StringUtils;
import lombok.Data;

import java.util.List;

@Data
public class MenuRow {

    private Integer id;

    private Integer parentId;

    private String name;

    private String icon;

    @Dictionary(key = "menu_type")
    private String type;

    private String path;

    private String routeId;

    private String openMethod;

    @Dictionary(key = "button_event")
    private String buttonType;

    private String useDevice;

    private String color;

    private String creator;

    private String createTime;

    private String updater;

    private String updateTime;

    private List<MenuRow> children;

    private List<RouteRow> routeRows;

    public static MenuRow build(Menu menu){
        MenuRow row = new MenuRow();
        row.setId(menu.getId());
        row.setParentId(menu.getParentId());
        row.setName(menu.getName());
        row.setIcon(menu.getIcon());
        row.setType(menu.getType());
        row.setUseDevice(menu.getUseDevice());
        row.setRouteId(StringUtils.isNotNull(menu.getRouteId()) ? menu.getRouteId().toString() : null);
        row.setButtonType(menu.getButtonType());
        row.setColor(menu.getColor());
        row.setCreator(menu.getCreator());
        row.setCreateTime(DateUtils.dateToStringFormat(menu.getCreateTime(), DateUtils.YYYY_MM_DD_HH_MM_SS));
        row.setUpdater(menu.getUpdater());
        row.setUpdateTime(DateUtils.dateToStringFormat(menu.getUpdateTime(), DateUtils.YYYY_MM_DD_HH_MM_SS));
        return row;
    }

}
